package com.yfp.device.controller;


import com.yfp.device.domain.OrderCombo;
import com.yfp.device.domain.dto.OrderCreateDTO;
import com.yfp.device.domain.vo.DeviceActionStatusMakeVO;
import com.yfp.device.domain.vo.OrderCreateVO;
import com.yfp.device.service.OrderService;
import com.yfp.device.domain.R;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单控制层
 *
 * 
 * @since 2023-12-11 17:38:53
 */
@Tag(name = "订单接口")
@RestController
@RequestMapping("")
@RefreshScope
public class OrderController {


    private final OrderService orderService;

    public OrderController(OrderService orderService) {
        this.orderService = orderService;
    }

    /**
     * 生成订单测试数据
     *
     * @return 响应体
     */
    @GetMapping("genOrderData")
    public R<?> genOrderData(@RequestParam(value = "date") String date, @RequestParam(value = "days") Integer days) {
        return orderService.genOrderData(date, days);
    }


    /**
     * 设备发起菜品制作
     *
     * @param orderCombo
     * @return
     */
    @Operation(summary = "设备发起菜品制作")
    @PostMapping("/action/status/make")
    public R<DeviceActionStatusMakeVO> deviceActionStatusMake(@RequestBody OrderCombo orderCombo) {
        return orderService.deviceActionStatusMake(orderCombo);
    }


    /**
     * 查询订单支付状态
     *
     * @param preOrderId
     * @return
     */
    @Operation(summary = "查询订单支付状态")
    @PostMapping("/combo/pre_order/status")
    public Object getDeviceComboPreOrderStatus(@ApiParam(value = "订单id") @NotNull(message = "订单id不能为空") String preOrderId) {
        return orderService.getDeviceComboPreOrderStatus(preOrderId);
    }

    @Operation(summary = "创建订单", description = "设备创建订单使用")
    @PostMapping("/combo/pre_order")
    public R<OrderCreateVO> deviceComboPreOrderCreate(@RequestBody OrderCreateDTO orderCreateDTO) {
        OrderCreateVO orderCreateVO = orderService.deviceComboPreOrderCreate(orderCreateDTO);
        return R.ok(orderCreateVO);
    }

    @Operation(summary = "设备聚合支付二维码扫描")
    @GetMapping("/int_pay/qr_code/{session_id}")
    public String payIntQrCodeUrlApply(@RequestHeader("User-Agent") String userAgent, @PathVariable("session_id") String sessionId) {
        return orderService.payChanelApply(userAgent, sessionId);
    }

    @Operation(summary = "修改订单状态")
    @PutMapping("/updateOrderStatus")
    public R updateOrderStatus(@RequestBody List<String> orderDetailIds){
        orderService.updateOrderStatus(orderDetailIds);
        return R.ok();
    }



}
